namespace Framework
{
    public class SimpleTypeDef
    {
        public string Name { get; }
        public string TypeName { get; }
        public byte TypeValue { get; }
        public bool IsValueType { get { return TypeValue == 1; } }
        public bool IsString { get { return TypeValue == 2; } }
        public bool IsEnum { get { return TypeValue == 3; } }
        public bool IsArray { get { return TypeValue == 4; } }
        public bool IsClass { get { return TypeValue == 5; } }
        public SimpleTypeDef(string value)
        {
            value = value.Replace(" ", "");
            Name = value;
            TypeName = value;
            if (value.IndexOf("index<") != -1 && value.IndexOf(">") == value.Length - 1)
            {
                Name = "index";
                TypeName = value.Substring(6, value.Length - 7);
            }
            if (value.StartsWith("index#"))
            {
                Name = "index";
                TypeName = value.Substring(6, value.Length - 6);
            }
            if (TypeName == "bool"
            || TypeName == "byte"
            || TypeName == "int"
            || TypeName == "float"
            || TypeName == "short"
            || TypeName == "long"
            )
            {
                TypeValue = 1;
                return;
            }
            if (TypeName == "string")
            {
                TypeValue = 2;
                return;
            }
            if (value.StartsWith("enum#"))
            {
                TypeValue = 3;
                TypeName = value.Substring(5, value.Length - 5);
                return;
            }
            if (value.IndexOf("enum<") != -1 && value.IndexOf(">") == value.Length - 1)
            {
                TypeValue = 3;
                TypeName = value.Substring(5, value.Length - 6);
                return;
            }
            var arrayIndex = value.IndexOf("[]");
            if (arrayIndex != -1)
            {
                TypeValue = 4;
                TypeName = value.Substring(0, arrayIndex);
                return;
            }
            TypeValue = 5;
        }
        public string GetInfo()
        {
            return TypeValue + ":" + TypeName;
        }
    }
}